package com.emperor.controller.vmservice;

import com.emperor.dto.NodeDto;
import com.emperor.entity.Business;
import com.emperor.result.Result;
import com.emperor.service.NodeService;
import com.emperor.vo.SkuClassPageVo;
import com.emperor.vo.VmListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vm-service/node")
@Api(tags = " 点位管理")
public class NodeController {
    @Autowired
    private NodeService nodeService;

    /**
     * 点位搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param regionId
     * @return
     */
    @ApiOperation("点位搜索")
    @GetMapping("/search")
    public SkuClassPageVo findAll(Integer pageIndex, Integer pageSize, String regionId) {
        SkuClassPageVo vo = nodeService.findAll(pageIndex, pageSize, regionId);
        return vo;
    }

    /**
     * 查询商圈列表
     *
     * @return
     */
    @ApiOperation("查询商圈列表")
    @GetMapping("/businessType")
    public Result<List<Business>> findBusiness() {
        List<Business> business = nodeService.findBusiness();
        return Result.success(business);
    }

    // TODO 暂时不使用也没有完成找不到表
    @ApiOperation(" 获取点位详情")
    @GetMapping("/vmList/{nodeId}")
    public VmListVo findNodeById(@PathVariable Integer nodeId) {
        VmListVo vo = nodeService.findNodeById(nodeId);
        return vo;
    }

    @ApiOperation("修改点位")
    @PutMapping("/{nodeId}")
    public Result updateNode(@PathVariable Integer nodeId, @RequestBody NodeDto dto) {
        nodeService.updateNode(nodeId, dto);
        return Result.success();
    }

    @ApiOperation("删除点位")
    @DeleteMapping("/{id}")
    public Result deleteNode(@PathVariable Integer id) {
        nodeService.deleteNode(id);
        return Result.success();
    }

    @GetMapping("/count")
    @ApiOperation("点位数量")
    public Result<Integer> count() {
       Integer integer= nodeService.count();
        return Result.success(integer);
    }
}
